package domain;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;

import javax.persistence.Access;
import javax.persistence.AccessType;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.hibernate.validator.constraints.NotBlank;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Access(AccessType.PROPERTY)
public class Painting extends DomainEntity {
	//Constructors

	public Painting() {
		super();
		comments = new HashSet<Comment>();
		ownershipHistories = new HashSet<OwnershipHistory>();
		auctions = new HashSet<Auction>();
			
	}


	//Attributes
	private String title;
	private String author;
	private Date date;
	private Money appraisal;
	
	@NotBlank
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	@NotBlank
	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}
	
	@NotNull
	@Past
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Valid
	@NotNull
	public Money getAppraisal() {
		return appraisal;
	}

	public void setAppraisal(Money appraisal) {
		this.appraisal = appraisal;
	}
	
	// Relationships//
	private Customer customer;
	private Gallery gallery;
	private Collection<Auction> auctions;
	private Collection<Comment> comments;
	private Collection<OwnershipHistory> ownershipHistories;
	
	@NotNull
	@Valid
	@ManyToOne(optional = false)
	public Customer getCustomer() {
		return customer;
	}
	
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	@Valid
	@ManyToOne(optional = true)
	public Gallery getGallery() {
		return gallery;
	}

	public void setGallery(Gallery gallery) {
		this.gallery = gallery;
	}
	
	@OneToMany(mappedBy = "painting")
	public Collection<Auction> getAuctions() {
		return auctions;
	}
	public void setAuctions(Collection<Auction> auctions) {
		this.auctions = auctions;
	}
	
	@OneToMany(mappedBy = "painting")
	public Collection<Comment> getComments() {
		return comments;
	}

	public void setComments(Collection<Comment> comments) {
		this.comments = comments;
	}
	
	@OneToMany(mappedBy = "painting")
	public Collection<OwnershipHistory> getOwnershipHistories() {
		return ownershipHistories;
	}

	public void setOwnershipHistories(Collection<OwnershipHistory> ownershipHistories) {
		this.ownershipHistories = ownershipHistories;
	}
}
